package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.mapper;

import com.iwhalecloud.citybrain.flow.platform.manager.common.client.HttpFlowRecordsQueryDto;
import com.iwhalecloud.citybrain.flow.platform.manager.common.client.HttpGetTaskDto;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.monitor.FlowTaskTraceVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.monitor.HttpFlowNodeRecordsQueryVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.monitor.HttpFlowRecordsQueryVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.task.TaskCandidateQueryVo;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.entities.FlowTaskTrace;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.entities.FlowTaskTraceExample;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;

public interface FlowTaskTraceDAO {
    long countByExample(FlowTaskTraceExample example);

    int deleteByExample(FlowTaskTraceExample example);

    int deleteByPrimaryKey(String id);

    int insert(FlowTaskTrace record);

    int insertSelective(FlowTaskTrace record);

    List<FlowTaskTrace> selectByExample(FlowTaskTraceExample example);

    /**
     * flow_task_trace 左联结 act_ru_identityLink表查询
     * @param example
     * @return
     */
    List<FlowTaskTrace> selectByExample2(FlowTaskTraceExample example);

    /**
     * 返回包含流程实例参数任务实例
     * @param example
     * @return
     */
    List<FlowTaskTrace> selectProcessVariableByExample(FlowTaskTraceExample example);

    FlowTaskTrace selectByPrimaryKey(String id);

    FlowTaskTrace selectByProIdAndTaskId(@Param("proId")String proId,@Param("taskId")String taskId);

    int updateByExampleSelective(@Param("record") FlowTaskTrace record, @Param("example") FlowTaskTraceExample example);

    int updateByExample(@Param("record") FlowTaskTrace record, @Param("example") FlowTaskTraceExample example);

    int updateByPrimaryKeySelective(FlowTaskTrace record);

    int updateByPrimaryKey(FlowTaskTrace record);

    int updateByTaskIdAndProcId(FlowTaskTrace record);

    int updateAssignInfoByTaskId(FlowTaskTrace record);

    int updateTaskByProcId(String proId,String proDefId);

    int updateExecutionByProcId(String proId,String proDefId);

    List<FlowTaskTrace> getFlowTaskTraceByTaskIdAndUser(TaskCandidateQueryVo taskCandidateQueryVo);

    List<FlowTaskTrace> getFlowTaskByModelAndUser(TaskCandidateQueryVo taskCandidateQueryVo);

    /**
     * 获取我的经办任务列表
     * @param example
     * @return
     */
    List<FlowTaskTrace> getDoneTaskTrace(FlowTaskTraceExample example);

    /**
     * 根据流程实例ID和节点编码批量查询审批信息
     * @param httpFlowRecordsQueryDto
     * @return
     */
    List<HttpFlowRecordsQueryVo> getFlowRecordsByTaskIdAndProcessId(HttpFlowRecordsQueryDto httpFlowRecordsQueryDto);

    /**
     * 根据流程模型编码查询流程实例列表
     * @param httpGetTaskDto
     * @return
     */
    List<HttpFlowNodeRecordsQueryVo> getFlowRecordsByModelKey(HttpGetTaskDto httpGetTaskDto);

    /**
     * 根据用户ID查询候选的任务列表
     * @param userId
     * @return
     */
    List<HttpFlowRecordsQueryVo> getTasksByCandidateUser(@Param("userId")String userId,@Param("orgIds") List<String> orgIds,@Param("roleIds") List<String> roleIds,@Param("positionIds") List<String> positionIds);


    /**
     * 根据流程id，查询每个节点最近的审批信息（驳回多次，只取最新一次审批结果）
     *
     * @param processInstanceId 流程实例id
     * @return
     */
    List<FlowTaskTrace> getAllLastTaskRecords(String processInstanceId);

    /**
     * 从flow_task_trace表中根据节点名称或者节点编码筛选流程实例id
     * @param
     * @return
     */
    List<FlowTaskTrace> queryProcessInstanceIdByTaskNameAndTaskCode(@Param("currentNodeName")String currentNodeName,@Param("currentNodeCode")String currentNodeCode,@Param("processInstanceIds") List<String> processInstanceIds);


    /**
     * 从flow_task_trace表中根据流程实例id查找当前任务处理人
     * @param processInstanceId
     * @return
     */
    List<String> queryAssignFromFlowTaskTrace(String processInstanceId);

    /**
     * 根据用户id、角色id、组织id在act_ru_identityLink表中查找流程实例id
     * @param userId
     * @param roleIds
     * @param organizationIds
     * @return
     */
    List<String> getInstanceIdByUserIdAndGroupId(@Param("userId") String userId, @Param("roleIds") List<String> roleIds, @Param("organizationIds") List<String>  organizationIds,@Param("positions") List<String>  positions);

    /**
     * 根据流程id查询当前流程在什么节点
     */
    String queryCurrentNodeByFlowId(String flowId);

    /**
     * 根据流程id更新指派人3
     */
    int updateApprover(Map paramMap);

    /**
     * 根据流程id查询taskid
     */
    String querytaskIdByFlowId(String flowId);
}